import { BASE_URL } from "./config"

class MyRequest {
  constructor(baseURL) {
    this.baseURL = baseURL
  }
  request(options) {
    return new Promise((resolve, reject)=>{
        wx.request({
          ...options,
          url: this.baseURL + options.url,
          success: (result) => {
            resolve(result.data)
          },
          fail: reject
        })
    })
  }
  get(options){
    return this.request({...options, method:'get'})
  }
  post(options){
    return this.request({...options, method:'post'})
  }
}
export const BaseRequest = new MyRequest(BASE_URL)
// export const TestRequest = new MyRequest('http://codercba.com:9002/')